package com.tongji.seller.view.comp
{
	import com.tongji.seller.events.DelStoreSceneEvent;
	import com.tongji.seller.events.utilsEvent.BubblesEvent;
	import com.tongji.seller.model.StoreSceneModel;
	import com.tongji.seller.model.UserModel;
	
	import mx.binding.utils.BindingUtils;
	import mx.controls.Alert;
	
	import org.robotlegs.mvcs.Mediator;
	
	/**
	 *
	 * @author caddy
	 * @date 2011-12-29
	 */
	public class CustomShowCompMediatore extends Mediator
	{
		[Inject]
		public var view:CustomShowComp;
		
		[Inject]
		public var storeSceneModel:StoreSceneModel;
		
		[Inject]
		public var userModel:UserModel;
		
		override public function onRegister():void
		{
			BindingUtils.bindProperty(view, "sceneArray", storeSceneModel, "selectedSceneArray");
			addViewListener(BubblesEvent.DELETE_SELECT_SCENE, removedSceneHandler, BubblesEvent);
/*			addContextListener(BubblesEvent.DELETE_SELECT_SCENE, removedSceneHandler, BubblesEvent);
*/		}
				
		/**
		 * 移除一个已选择的场景 
		 * @param event
		 * 
		 */		
		private function removedSceneHandler(event:BubblesEvent):void
		{
			dispatch(new DelStoreSceneEvent(DelStoreSceneEvent.DEL_STORE_SYSTEM_SCENE, userModel.currentUserID, event.object.sid));
			
			/*var deleteScene:Object = event.object;
			storeSceneModel.savedSceneArray.removeItemAt(storeSceneModel.savedSceneArray.getItemIndex(event.object));

			for (var i:int = 0; i < storeSceneModel.sceneArray.length; i++)
			{
				if (storeSceneModel.sceneArray.getItemAt(i).sid == event.object.sid)
				{
					storeSceneModel.sceneArray.getItemAt(i).UserSceneState = 0;
				}
			}
			view.createDataProvider(storeSceneModel.savedSceneArray);
			storeSceneModel.sceneArray.refresh();*/
		}
	}
}